package com.acwing.partition2;

import java.io.*;

/**
 * @author `RKC`
 * @date 2022/1/3 9:28
 */
public class AC168生日蛋糕 {

    private static final int N = 10010, M = 25, INF = 0x3f3f3f3f;
    private static int n = 0, m = 0, answer = INF;
    //预处理出来每一层的累计最小体积和累计最小侧面积，从高到低编号从1开始
    private static int[] sumMinv = new int[M], sumMins = new int[M], radius = new int[M], height = new int[M];

    private static final BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
    private static final BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(System.out));

    public static void main(String[] args) throws IOException {
        n = Integer.parseInt(reader.readLine());
        m = Integer.parseInt(reader.readLine());
        init();
        dfs(m, 0, 0);
        writer.write((answer == INF ? 0 : answer) + "\n");
        writer.flush();
    }

    private static void init() {
        for (int i = 1; i <= m; i++) {
            //对于第i层的累计最小体积：V=上一层体积+π*r^2*h，对于第i层的累计最小侧面积：S=上一层侧面积+2π*r*h
            sumMinv[i] = sumMinv[i - 1] + i * i * i;
            sumMins[i] = sumMins[i - 1] + i * i;
        }
        //设置一个哨兵，m+1层不存在，减少了边界情况的判断
        radius[m + 1] = height[m + 1] = INF;
    }

    private static void dfs(int u, int v, int s) {
        if (v + sumMinv[u] > n || s + sumMins[u] >= answer) return;
        if (s + 2 * (n - v) / radius[u + 1] >= answer) return;
        if (u == 0) {
            if (v == n) answer = s;
            return;
        }
        //在有效范围内枚举第u层的半径和高度
        for (int r = Math.min(radius[u + 1] - 1, (int) Math.sqrt((n - v - sumMinv[u - 1]) / u)); r >= u; r--) {
            for (int h = Math.min(height[u + 1] - 1, (n - sumMinv[u - 1] - v) / (r * r)); h >= u; h--) {
                height[u] = h;
                radius[u] = r;
                //m层时就加上固定的一个上层表面积
                int temp = u == m ? r * r : 0;
                dfs(u - 1, v + r * r * h, s + 2 * r * h + temp);
            }
        }
    }
}
